<template>
	<view>
		<button @click="callSetStorage()">setStorage</button>
		<button @click="callGetStorage()">获取缓存</button>
		<button @click="callGetStorageInfo()">获取字段列表</button>
		<button @click="callRemove()" plain="true">删除</button>
		<button @click="callClear()">清空</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			onFunCall(){
				// 异步接口：直接往下走，后面给我一个接口拿到他就好了
				name = uni.getStorage("");
				
				// 同步接口：必须有返回值了，才会往下走
				// 不好之处：网络卡在那里了，好处：一定拿得到name
				name = uni.getStorageSync("");
				pwd="55555";
			
			},
			callSetStorage(){
				// 传入一个对象
				uni.setStorage({
					key:"username",
					data:"yyx",
					success(){
						console.log("存储username 成功回调");
					},
					fail(){
						console.error("存储username 存储失败");
					},
					// 完成，用得少
					// complete(){}
				})
			},
			callGetStorage(){
				uni.getStorage({
					key:"username",
					success:function(result){
						console.log("获取本地缓存成功："+ result.data);
					},
					fail:function(result){
						console.error("获取本地缓存失败："+JSON.stringify(result));
						console.error("获取本地缓存失败："+result.errMsg);
					},
				})
			},
			callGetStorageInfo(){
				uni.getStorageInfo({
					success:function(result){
						console.log("storageInfo----->"+JSON.stringify(result));
						console.log("storageInfo----->"+result.keys);
					}
				})
			},
			callRemove(){
				uni.removeStorage({
					key:"username",
					success(){
						console.log("removeStorage  success");
					},
					fail(){
						console.error("removeStorage  error");
					},
				})
			},
			callClear(){
				uni.clearStorage()
			}
		}
	}
</script>

<style>

</style>
